// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cstdint>
#include <memory>
#include <utility>


#include <nebula/types/type_fwd.h>
#include <nebula/util/type_fwd.h>
#include <turbo/base/macros.h>

namespace nebula::csv {

    class BlockParser;

    struct ConvertOptions;

    class TURBO_EXPORT ColumnDecoder {
    public:
        virtual ~ColumnDecoder() = default;

        /// Spawn a task that will try to convert and insert the given CSV block
        virtual Future<std::shared_ptr<Array>> Decode(
                const std::shared_ptr<BlockParser> &parser) = 0;

        /// Construct a strictly-typed ColumnDecoder.
        static turbo::Result<std::shared_ptr<ColumnDecoder>> create(MemoryPool *pool,
                                                           std::shared_ptr<DataType> type,
                                                           int32_t col_index,
                                                           const ConvertOptions &options);

        /// Construct a type-inferring ColumnDecoder.
        /// Inference will run only on the first block, the type will be frozen afterwards.
        static turbo::Result<std::shared_ptr<ColumnDecoder>> create(MemoryPool *pool, int32_t col_index,
                                                           const ConvertOptions &options);

        /// Construct a ColumnDecoder for a column of nulls
        /// (i.e. not present in the CSV file).
        static turbo::Result<std::shared_ptr<ColumnDecoder>> MakeNull(MemoryPool *pool,
                                                               std::shared_ptr<DataType> type);

    protected:
        ColumnDecoder() = default;
    };

}  // namespace nebula::csv
